﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace Windstamp.Utility.BookDownload.PWADSWinForm {
    public partial class AntispiderShowVerifyForm : Form {
        /// <summary>
        /// 链接
        /// </summary>
        public string AntispiderShowVerifyUrl { get; set; }

        /// <summary>
        /// 状态
        /// </summary>
        public string Status { get; set; }

        public AntispiderShowVerifyForm() {
            InitializeComponent();
            Status = "open";
        }

        void AntispiderShowVerifyForm_Load(object sender, EventArgs e) {
            InitWebBrowser();
        }

        [STAThread]
        public void InitWebBrowser() {
            webAntispiderShowVerify.Visible = true;
            webAntispiderShowVerify.Url = new System.Uri(AntispiderShowVerifyUrl, UriKind.Absolute);
        }

        private void webAntispiderShowVerify_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) {
            if(e.KeyCode == Keys.Enter) {
                ((AntispiderShowVerifyForm)((WebBrowser)sender).Parent).Status = "finished";
            }

            if(e.KeyCode == Keys.Escape) {
                Dispose();
                Close();
            }
        }

        private void webAntispiderShowVerify_Navigating(object sender, WebBrowserNavigatingEventArgs e) {
            if(((AntispiderShowVerifyForm)((WebBrowser)sender).Parent).Status == "finished") {
                Dispose();
                Close();
            }
        }
    }
}
